package com.zytech.zspider.transformer;

import com.zytech.modules.lang.Lookups;
import com.zytech.zspider.transformer.spi.SpiderDefinitionTransformerFactory;
import com.zytech.zspider.transformer.spi.SpiderDefinitionTransformerFactoryNotFoundException;

/**
 * @author siuming
 */
public final class SpiderDefinitionTransformers {
    private static final SpiderDefinitionTransformers ME = new SpiderDefinitionTransformers();
    private static final SpiderDefinitionTransformerFactory DEFAULT_TRANSFORMER_FACTORY = new SpiderDefinitionTransformerFactory() {
        @Override
        public SpiderDefinitionTransformer create() {
            return new DefaultSpiderDefinitionTransformer();
        }
    };

    /**
     * @return
     */
    public static SpiderDefinitionTransformers me() {
        return ME;
    }

    /**
     * @return
     */
    public SpiderDefinitionTransformer usingDefault() {
        return DEFAULT_TRANSFORMER_FACTORY.create();
    }

    /**
     * @return
     */
    public SpiderDefinitionTransformer usingCustom() {
        SpiderDefinitionTransformerFactory transformerFactory = Lookups.lookup(SpiderDefinitionTransformerFactory.class);
        if (null == transformerFactory) {
            throw new SpiderDefinitionTransformerFactoryNotFoundException("Not found SpiderDefinitionTransformerFactory spi.");
        }
        return transformerFactory.create();
    }

    private SpiderDefinitionTransformers() {
    }
}
